#pragma once
#include <rviz_common/panel.hpp>
#include "rviz_custom_plugins/utils/interactive_marker_thread.h"
#include <rviz_common/config.hpp>
#include "rviz_custom_plugins/panels/ui_snapshot_point_panel.h"
#include "rviz_custom_plugins/viewmodels/point_model.h"
#include "rviz_custom_plugins/utils/bag_map_notifier.h"



using rviz_common::Config;
using rviz_custom_plugins::utils::InteractiveMarkerThread;
using rviz_custom_plugins::viewmodels::PointModel;
using rviz_custom_plugins::utils::BagMapNotifier;


namespace rviz_custom_plugins
{

namespace panels
{

class SnapshotPointPanel : public rviz_common::Panel
{
    Q_OBJECT

public:
    explicit SnapshotPointPanel(QWidget *parent = nullptr);

    void load(const Config& config) override;

private:

    inline static const QString ROW = "row";

    BagMapNotifier* mapNotifier;

    Ui::snapshotPointPanel* ui{ nullptr };
    std::shared_ptr<InteractiveMarkerThread> markerThread;

    PointModel* tableModel;

    void removeButtonClicked();
    void removeItem(int row);

private slots:
    void handleMarkerFeedback(InteractiveMarkerServer::FeedbackConstSharedPtr feedback);
    void handleActiveStatusChanged(bool active);
    void handlerMarkersReorder(int row, std::list<InteractiveMarker>& markers);

    void handleMapPointSelected(QString nameSpace, int pclIndex, pcl::PointXYZINormal& point);

    void handleProjectLoaded(QSharedPointer<QVariantMap> projectData);
    void handleProjectSaved(QSharedPointer<QVariantMap> projectData);
    void handleProjectClosed(QSharedPointer<QVariantMap> projectData);

};

}


}
